package com.sf.dlb.web.config;

import com.sf.dlb.web.interceptor.LoginHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 接口url拦截器
 */
@Configuration
public class UrlInterceptConfig extends WebMvcConfigurerAdapter {
    //需要拦截的url
    private static String[] addPathPatterns=new String[]{"/**"};
    //不需要拦截的url
    private static String[] excludePathPatterns=new String[]
            {"/",
            "/v1/admin/**",
            "/v1/sysUser/login",
            };
    @Autowired
    private LoginHandlerInterceptor loginHandlerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        registry.addInterceptor(loginHandlerInterceptor)
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //添加视图与Controllers的映射
//        registry.addViewController("/").setViewName("login");
//        registry.addViewController("/index.html").setViewName("login");
//        registry.addViewController("/main.html").setViewName("dashboard");
        super.addViewControllers(registry);
    }
}